package cn.lycode.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.lycode.common.core.controller.BaseController;
import cn.lycode.common.core.domain.AjaxResult;
import cn.lycode.common.core.domain.model.ConditionDTO;
import cn.lycode.common.core.domain.model.SelectIdsDTO;
import cn.lycode.common.core.page.PageResult;
import cn.lycode.system.domain.dto.sysdict.SysDictTypeAddDTO;
import cn.lycode.system.domain.dto.sysdict.SysDictTypeUpDTO;
import cn.lycode.system.domain.entity.SysDictType;
import cn.lycode.system.service.SysDictTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 字典类型 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/sys-dictType")
@RequiredArgsConstructor
public class SysDictTypeController extends BaseController {

    private final SysDictTypeService sysDictTypeService;

    @SaCheckPermission(value = "sys:dictType:list")
    @PostMapping("/list")
    public AjaxResult<PageResult<SysDictType>> list(@RequestBody ConditionDTO dto) {
        return AjaxResult.success(sysDictTypeService.list(dto));
    }

    @SaCheckPermission(value = "sys:dictType:add")
    @PostMapping("/add")
    public AjaxResult<Object> add(@Valid @RequestBody SysDictTypeAddDTO dto) {
        return toAjax(sysDictTypeService.add(dto));
    }

    @SaCheckPermission(value = "sys:dictType:list")
    @GetMapping("/{id}")
    public AjaxResult<SysDictType> detail(@PathVariable Long id) {
        return AjaxResult.success(sysDictTypeService.detail(id));
    }

    @SaCheckPermission(value = "sys:dictType:update")
    @PostMapping("/update")
    public AjaxResult<Object> update(@Valid @RequestBody SysDictTypeUpDTO dto) {
        return toAjax(sysDictTypeService.update(dto));
    }

    @SaCheckPermission(value = "sys:dictType:delete")
    @PostMapping("/remove")
    public AjaxResult<Object> remove(@RequestBody SelectIdsDTO dto) {
        return toAjax(sysDictTypeService.remove(dto));
    }



    @SaCheckPermission(value = "sys:dictType:delete")
    @PostMapping("/lock")
    public AjaxResult<Object> lock(@RequestBody SelectIdsDTO dto) {
        return toAjax(sysDictTypeService.lock(dto));
    }



    /**
     * 下拉字典类型查询, 用于代码生成下拉框
     */
    @SaCheckPermission(value = "sys:dictType:list")
    @GetMapping("/selectOptionsType")
    public AjaxResult<List<SysDictType>> selectOptionType() {
        return AjaxResult.success(sysDictTypeService.selectOptionsType());
    }
}
